import Dialog from "@vant/weapp/dialog/dialog";

Component({
    properties: {
        treeData: {
            type: Array,
            value: []
        }
    },
    data: {
        currentIndex: 0
    },
    ready() {
    },
    methods: {
        changeCategory(e) {
            const currentIndex = e.currentTarget.dataset.index
            this.setData({currentIndex})
        },
        addCategory() {
            this.triggerEvent('addCategory')
        },
        addContent() {
            if (this.data.treeData.length === 0) {
                Dialog.alert({title: '提示', message: '请先添加分类'})
                return
            }
            const currentCategory = this.data.treeData[this.data.currentIndex]
            this.triggerEvent('addContent', currentCategory)
        },
        showContentInfo(e) {
            const id = e.currentTarget.dataset.id
            this.triggerEvent('showContentInfo', id)
        }
    }
});
